bl_info = {
	"name": "Translation",
	"description": "一键切换中英文翻译",
	"author": "Baka_Akari",
	"version": (0, 0, 3),
	"blender": (3, 3, 0),
	"warning": "",
	"doc_url": "",
	"tracker_url": "",
	"category": "3D View"
}
import bpy
from bpy.utils import register_class, unregister_class

def translation_draw(self, context):
    layout = self.layout
    if context.preferences.view.language == "en_US":
        Buttontext = "Switch CN"
    else:
        Buttontext = "切换英文"
    layout.operator(operator="object.translation_op", text=Buttontext)

class Translation_Operation(bpy.types.Operator):
    bl_idname = "object.translation_op"
    bl_label = "切换中英文"

    def execute(self, context):
        viewlanguage = context.preferences.view.language
        prefview = context.preferences.view
        if viewlanguage == "zh_CN":
            context.preferences.view.language = "en_US"
        else:
            context.preferences.view.language = "zh_CN"
            prefview.use_translate_new_dataname = False

        return{'FINISHED'}

classes = (Translation_Operation,
            )

def register():
    global classes
    for cls in classes:
        register_class(cls)
    bpy.types.STATUSBAR_HT_header.append(translation_draw)
    # bpy.types.TOPBAR_MT_window
    

def unregister():
    global classes
    for cls in classes:
        unregister_class(cls)
    bpy.types.STATUSBAR_HT_header.remove(translation_draw)

if __name__ == "__main__":
    register()